//-----------------------------------------------------------------------
// <copyright file="a_ProductDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_ProductDAOBase
    {
        #region Common methods
        public virtual a_Product Createa_ProductFromReader(IDataReader reader)
        {
            a_Product item = new a_Product();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("ProdID"))) item.ProdID = (int)reader["ProdID"];
                if (!reader.IsDBNull(reader.GetOrdinal("ParentID"))) item.ParentID = (int)reader["ParentID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomPartNum"))) item.DomPartNum = (string)reader["DomPartNum"];
                if (!reader.IsDBNull(reader.GetOrdinal("MfgPartNum"))) item.MfgPartNum = (string)reader["MfgPartNum"];
                if (!reader.IsDBNull(reader.GetOrdinal("StoreID"))) item.StoreID = (int)reader["StoreID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SupplierID"))) item.SupplierID = (int)reader["SupplierID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID"))) item.CatID = (int)reader["CatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatName"))) item.CatName = (string)reader["CatName"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatID"))) item.SubCatID = (int)reader["SubCatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatName"))) item.SubCatName = (string)reader["SubCatName"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2ID"))) item.SubCat2ID = (int)reader["SubCat2ID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2Name"))) item.SubCat2Name = (string)reader["SubCat2Name"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID2"))) item.CatID2 = (int)reader["CatID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatName2"))) item.CatName2 = (string)reader["CatName2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatID2"))) item.SubCatID2 = (int)reader["SubCatID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatName2"))) item.SubCatName2 = (string)reader["SubCatName2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2ID2"))) item.SubCat2ID2 = (int)reader["SubCat2ID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2Name2"))) item.SubCat2Name2 = (string)reader["SubCat2Name2"];
                if (!reader.IsDBNull(reader.GetOrdinal("MfgID"))) item.MfgID = (int)reader["MfgID"];
                if (!reader.IsDBNull(reader.GetOrdinal("MfgName"))) item.MfgName = (string)reader["MfgName"];
                if (!reader.IsDBNull(reader.GetOrdinal("BrandID"))) item.BrandID = (int)reader["BrandID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Brand"))) item.Brand = (string)reader["Brand"];
                if (!reader.IsDBNull(reader.GetOrdinal("Model"))) item.Model = (string)reader["Model"];
                if (!reader.IsDBNull(reader.GetOrdinal("Overview"))) item.Overview = (string)reader["Overview"];
                if (!reader.IsDBNull(reader.GetOrdinal("Features"))) item.Features = (string)reader["Features"];
                if (!reader.IsDBNull(reader.GetOrdinal("OtherKeywords"))) item.OtherKeywords = (string)reader["OtherKeywords"];
                if (!reader.IsDBNull(reader.GetOrdinal("RelatedGrpID"))) item.RelatedGrpID = (string)reader["RelatedGrpID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Colors"))) item.Colors = (string)reader["Colors"];
                if (!reader.IsDBNull(reader.GetOrdinal("Sizes"))) item.Sizes = (string)reader["Sizes"];
                if (!reader.IsDBNull(reader.GetOrdinal("OptionID1"))) item.OptionID1 = (int)reader["OptionID1"];
                if (!reader.IsDBNull(reader.GetOrdinal("OptionID2"))) item.OptionID2 = (int)reader["OptionID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("OptionID3"))) item.OptionID3 = (int)reader["OptionID3"];
                if (!reader.IsDBNull(reader.GetOrdinal("SpecSheetID"))) item.SpecSheetID = (int)reader["SpecSheetID"];
                if (!reader.IsDBNull(reader.GetOrdinal("RelProductsGrpID"))) item.RelProductsGrpID = (int)reader["RelProductsGrpID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Price_MSRP"))) item.Price_MSRP = (decimal)reader["Price_MSRP"];
                if (!reader.IsDBNull(reader.GetOrdinal("Price_Internet"))) item.Price_Internet = (decimal)reader["Price_Internet"];
                if (!reader.IsDBNull(reader.GetOrdinal("Price_Cost"))) item.Price_Cost = (decimal)reader["Price_Cost"];
                if (!reader.IsDBNull(reader.GetOrdinal("Featured"))) item.Featured = (byte)reader["Featured"];
                if (!reader.IsDBNull(reader.GetOrdinal("QtySoldToDate"))) item.QtySoldToDate = (int)reader["QtySoldToDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("QtyOnHand"))) item.QtyOnHand = (int)reader["QtyOnHand"];
                if (!reader.IsDBNull(reader.GetOrdinal("QtyReserved"))) item.QtyReserved = (int)reader["QtyReserved"];
                if (!reader.IsDBNull(reader.GetOrdinal("QtyAvailable"))) item.QtyAvailable = (int)reader["QtyAvailable"];
                if (!reader.IsDBNull(reader.GetOrdinal("Weight"))) item.Weight = (double)reader["Weight"];
                if (!reader.IsDBNull(reader.GetOrdinal("IntroDate"))) item.IntroDate = (DateTime)reader["IntroDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("ClickCount"))) item.ClickCount = (int)reader["ClickCount"];
                if (!reader.IsDBNull(reader.GetOrdinal("RatingAvg"))) item.RatingAvg = (int)reader["RatingAvg"];
                if (!reader.IsDBNull(reader.GetOrdinal("RatingCount"))) item.RatingCount = (int)reader["RatingCount"];
                if (!reader.IsDBNull(reader.GetOrdinal("Image_hasS"))) item.Image_hasS = (bool)reader["Image_hasS"];
                if (!reader.IsDBNull(reader.GetOrdinal("Image_hasM"))) item.Image_hasM = (bool)reader["Image_hasM"];
                if (!reader.IsDBNull(reader.GetOrdinal("Image_hasL"))) item.Image_hasL = (bool)reader["Image_hasL"];
                if (!reader.IsDBNull(reader.GetOrdinal("LibImageName"))) item.LibImageName = (string)reader["LibImageName"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsDelete"))) item.IsDelete = (bool)reader["IsDelete"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsActive"))) item.IsActive = (bool)reader["IsActive"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsPromoEligible"))) item.IsPromoEligible = (bool)reader["IsPromoEligible"];
                if (!reader.IsDBNull(reader.GetOrdinal("TempProdID"))) item.TempProdID = (int)reader["TempProdID"];
                if (!reader.IsDBNull(reader.GetOrdinal("TempParentID"))) item.TempParentID = (int)reader["TempParentID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom1"))) item.Custom1 = (string)reader["Custom1"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom2"))) item.Custom2 = (string)reader["Custom2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom3"))) item.Custom3 = (string)reader["Custom3"];
                if (!reader.IsDBNull(reader.GetOrdinal("Custom4"))) item.Custom4 = (string)reader["Custom4"];
                if (!reader.IsDBNull(reader.GetOrdinal("CustomDate"))) item.CustomDate = (DateTime)reader["CustomDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsTaxable"))) item.IsTaxable = (bool)reader["IsTaxable"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsShippable"))) item.IsShippable = (bool)reader["IsShippable"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsGiftCert"))) item.IsGiftCert = (bool)reader["IsGiftCert"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsPackage"))) item.IsPackage = (bool)reader["IsPackage"];
                if (!reader.IsDBNull(reader.GetOrdinal("NumImages"))) item.NumImages = (byte)reader["NumImages"];
                if (!reader.IsDBNull(reader.GetOrdinal("NumPDFs"))) item.NumPDFs = (byte)reader["NumPDFs"];
                if (!reader.IsDBNull(reader.GetOrdinal("NumVideos"))) item.NumVideos = (byte)reader["NumVideos"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_Product methods
            
        public virtual void Createa_Product(a_Product a_Product)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Products_ins");
                
                database.AddInParameter(dbCommand, "@ParentID", DbType.Int32, a_Product.ParentID);
                database.AddInParameter(dbCommand, "@DomPartNum", DbType.AnsiString, a_Product.DomPartNum);
                database.AddInParameter(dbCommand, "@MfgPartNum", DbType.AnsiString, a_Product.MfgPartNum);
                database.AddInParameter(dbCommand, "@StoreID", DbType.Int32, a_Product.StoreID);
                database.AddInParameter(dbCommand, "@SupplierID", DbType.Int32, a_Product.SupplierID);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_Product.CatID);
                database.AddInParameter(dbCommand, "@CatName", DbType.AnsiString, a_Product.CatName);
                database.AddInParameter(dbCommand, "@SubCatID", DbType.Int32, a_Product.SubCatID);
                database.AddInParameter(dbCommand, "@SubCatName", DbType.AnsiString, a_Product.SubCatName);
                database.AddInParameter(dbCommand, "@SubCat2ID", DbType.Int32, a_Product.SubCat2ID);
                database.AddInParameter(dbCommand, "@SubCat2Name", DbType.AnsiString, a_Product.SubCat2Name);
                database.AddInParameter(dbCommand, "@CatID2", DbType.Int32, a_Product.CatID2);
                database.AddInParameter(dbCommand, "@CatName2", DbType.AnsiString, a_Product.CatName2);
                database.AddInParameter(dbCommand, "@SubCatID2", DbType.Int32, a_Product.SubCatID2);
                database.AddInParameter(dbCommand, "@SubCatName2", DbType.AnsiString, a_Product.SubCatName2);
                database.AddInParameter(dbCommand, "@SubCat2ID2", DbType.Int32, a_Product.SubCat2ID2);
                database.AddInParameter(dbCommand, "@SubCat2Name2", DbType.AnsiString, a_Product.SubCat2Name2);
                database.AddInParameter(dbCommand, "@MfgID", DbType.Int32, a_Product.MfgID);
                database.AddInParameter(dbCommand, "@MfgName", DbType.AnsiString, a_Product.MfgName);
                database.AddInParameter(dbCommand, "@BrandID", DbType.Int32, a_Product.BrandID);
                database.AddInParameter(dbCommand, "@Brand", DbType.AnsiString, a_Product.Brand);
                database.AddInParameter(dbCommand, "@Model", DbType.AnsiString, a_Product.Model);
                database.AddInParameter(dbCommand, "@Overview", DbType.AnsiString, a_Product.Overview);
                database.AddInParameter(dbCommand, "@Features", DbType.AnsiString, a_Product.Features);
                database.AddInParameter(dbCommand, "@OtherKeywords", DbType.AnsiString, a_Product.OtherKeywords);
                database.AddInParameter(dbCommand, "@RelatedGrpID", DbType.AnsiString, a_Product.RelatedGrpID);
                database.AddInParameter(dbCommand, "@Colors", DbType.AnsiString, a_Product.Colors);
                database.AddInParameter(dbCommand, "@Sizes", DbType.AnsiString, a_Product.Sizes);
                database.AddInParameter(dbCommand, "@OptionID1", DbType.Int32, a_Product.OptionID1);
                database.AddInParameter(dbCommand, "@OptionID2", DbType.Int32, a_Product.OptionID2);
                database.AddInParameter(dbCommand, "@OptionID3", DbType.Int32, a_Product.OptionID3);
                database.AddInParameter(dbCommand, "@SpecSheetID", DbType.Int32, a_Product.SpecSheetID);
                database.AddInParameter(dbCommand, "@RelProductsGrpID", DbType.Int32, a_Product.RelProductsGrpID);
                database.AddInParameter(dbCommand, "@Price_MSRP", DbType.Currency, a_Product.Price_MSRP);
                database.AddInParameter(dbCommand, "@Price_Internet", DbType.Currency, a_Product.Price_Internet);
                database.AddInParameter(dbCommand, "@Price_Cost", DbType.Currency, a_Product.Price_Cost);
                database.AddInParameter(dbCommand, "@Featured", DbType.Byte, a_Product.Featured);
                database.AddInParameter(dbCommand, "@QtySoldToDate", DbType.Int32, a_Product.QtySoldToDate);
                database.AddInParameter(dbCommand, "@QtyOnHand", DbType.Int32, a_Product.QtyOnHand);
                database.AddInParameter(dbCommand, "@QtyReserved", DbType.Int32, a_Product.QtyReserved);
                database.AddInParameter(dbCommand, "@QtyAvailable", DbType.Int32, a_Product.QtyAvailable);
                database.AddInParameter(dbCommand, "@Weight", DbType.Double, a_Product.Weight);
                database.AddInParameter(dbCommand, "@IntroDate", DbType.DateTime, a_Product.IntroDate);
                database.AddInParameter(dbCommand, "@ClickCount", DbType.Int32, a_Product.ClickCount);
                database.AddInParameter(dbCommand, "@RatingAvg", DbType.Int32, a_Product.RatingAvg);
                database.AddInParameter(dbCommand, "@RatingCount", DbType.Int32, a_Product.RatingCount);
                database.AddInParameter(dbCommand, "@Image_hasS", DbType.Boolean, a_Product.Image_hasS);
                database.AddInParameter(dbCommand, "@Image_hasM", DbType.Boolean, a_Product.Image_hasM);
                database.AddInParameter(dbCommand, "@Image_hasL", DbType.Boolean, a_Product.Image_hasL);
                database.AddInParameter(dbCommand, "@LibImageName", DbType.AnsiString, a_Product.LibImageName);
                database.AddInParameter(dbCommand, "@IsDelete", DbType.Boolean, a_Product.IsDelete);
                database.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, a_Product.IsActive);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_Product.DomainID);
                database.AddInParameter(dbCommand, "@IsPromoEligible", DbType.Boolean, a_Product.IsPromoEligible);
                database.AddInParameter(dbCommand, "@TempProdID", DbType.Int32, a_Product.TempProdID);
                database.AddInParameter(dbCommand, "@TempParentID", DbType.Int32, a_Product.TempParentID);
                database.AddInParameter(dbCommand, "@Custom1", DbType.AnsiString, a_Product.Custom1);
                database.AddInParameter(dbCommand, "@Custom2", DbType.AnsiString, a_Product.Custom2);
                database.AddInParameter(dbCommand, "@Custom3", DbType.AnsiString, a_Product.Custom3);
                database.AddInParameter(dbCommand, "@Custom4", DbType.AnsiString, a_Product.Custom4);
                database.AddInParameter(dbCommand, "@CustomDate", DbType.DateTime, a_Product.CustomDate);
                database.AddInParameter(dbCommand, "@IsTaxable", DbType.Boolean, a_Product.IsTaxable);
                database.AddInParameter(dbCommand, "@IsShippable", DbType.Boolean, a_Product.IsShippable);
                database.AddInParameter(dbCommand, "@IsGiftCert", DbType.Boolean, a_Product.IsGiftCert);
                database.AddInParameter(dbCommand, "@IsPackage", DbType.Boolean, a_Product.IsPackage);
                database.AddInParameter(dbCommand, "@NumImages", DbType.Byte, a_Product.NumImages);
                database.AddInParameter(dbCommand, "@NumPDFs", DbType.Byte, a_Product.NumPDFs);
                database.AddInParameter(dbCommand, "@NumVideos", DbType.Byte, a_Product.NumVideos);
                database.AddOutParameter(dbCommand, "@ProdID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_Product.ProdID = (int)database.GetParameterValue(dbCommand, "@ProdID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_Product methods
        
        public virtual void Updatea_Product(a_Product a_Product)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Products_upd");            
                
                database.AddInParameter(dbCommand, "@ProdID", DbType.Int32, a_Product.ProdID);
                database.AddInParameter(dbCommand, "@ParentID", DbType.Int32, a_Product.ParentID);
                database.AddInParameter(dbCommand, "@DomPartNum", DbType.AnsiString, a_Product.DomPartNum);
                database.AddInParameter(dbCommand, "@MfgPartNum", DbType.AnsiString, a_Product.MfgPartNum);
                database.AddInParameter(dbCommand, "@StoreID", DbType.Int32, a_Product.StoreID);
                database.AddInParameter(dbCommand, "@SupplierID", DbType.Int32, a_Product.SupplierID);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_Product.CatID);
                database.AddInParameter(dbCommand, "@CatName", DbType.AnsiString, a_Product.CatName);
                database.AddInParameter(dbCommand, "@SubCatID", DbType.Int32, a_Product.SubCatID);
                database.AddInParameter(dbCommand, "@SubCatName", DbType.AnsiString, a_Product.SubCatName);
                database.AddInParameter(dbCommand, "@SubCat2ID", DbType.Int32, a_Product.SubCat2ID);
                database.AddInParameter(dbCommand, "@SubCat2Name", DbType.AnsiString, a_Product.SubCat2Name);
                database.AddInParameter(dbCommand, "@CatID2", DbType.Int32, a_Product.CatID2);
                database.AddInParameter(dbCommand, "@CatName2", DbType.AnsiString, a_Product.CatName2);
                database.AddInParameter(dbCommand, "@SubCatID2", DbType.Int32, a_Product.SubCatID2);
                database.AddInParameter(dbCommand, "@SubCatName2", DbType.AnsiString, a_Product.SubCatName2);
                database.AddInParameter(dbCommand, "@SubCat2ID2", DbType.Int32, a_Product.SubCat2ID2);
                database.AddInParameter(dbCommand, "@SubCat2Name2", DbType.AnsiString, a_Product.SubCat2Name2);
                database.AddInParameter(dbCommand, "@MfgID", DbType.Int32, a_Product.MfgID);
                database.AddInParameter(dbCommand, "@MfgName", DbType.AnsiString, a_Product.MfgName);
                database.AddInParameter(dbCommand, "@BrandID", DbType.Int32, a_Product.BrandID);
                database.AddInParameter(dbCommand, "@Brand", DbType.AnsiString, a_Product.Brand);
                database.AddInParameter(dbCommand, "@Model", DbType.AnsiString, a_Product.Model);
                database.AddInParameter(dbCommand, "@Overview", DbType.AnsiString, a_Product.Overview);
                database.AddInParameter(dbCommand, "@Features", DbType.AnsiString, a_Product.Features);
                database.AddInParameter(dbCommand, "@OtherKeywords", DbType.AnsiString, a_Product.OtherKeywords);
                database.AddInParameter(dbCommand, "@RelatedGrpID", DbType.AnsiString, a_Product.RelatedGrpID);
                database.AddInParameter(dbCommand, "@Colors", DbType.AnsiString, a_Product.Colors);
                database.AddInParameter(dbCommand, "@Sizes", DbType.AnsiString, a_Product.Sizes);
                database.AddInParameter(dbCommand, "@OptionID1", DbType.Int32, a_Product.OptionID1);
                database.AddInParameter(dbCommand, "@OptionID2", DbType.Int32, a_Product.OptionID2);
                database.AddInParameter(dbCommand, "@OptionID3", DbType.Int32, a_Product.OptionID3);
                database.AddInParameter(dbCommand, "@SpecSheetID", DbType.Int32, a_Product.SpecSheetID);
                database.AddInParameter(dbCommand, "@RelProductsGrpID", DbType.Int32, a_Product.RelProductsGrpID);
                database.AddInParameter(dbCommand, "@Price_MSRP", DbType.Currency, a_Product.Price_MSRP);
                database.AddInParameter(dbCommand, "@Price_Internet", DbType.Currency, a_Product.Price_Internet);
                database.AddInParameter(dbCommand, "@Price_Cost", DbType.Currency, a_Product.Price_Cost);
                database.AddInParameter(dbCommand, "@Featured", DbType.Byte, a_Product.Featured);
                database.AddInParameter(dbCommand, "@QtySoldToDate", DbType.Int32, a_Product.QtySoldToDate);
                database.AddInParameter(dbCommand, "@QtyOnHand", DbType.Int32, a_Product.QtyOnHand);
                database.AddInParameter(dbCommand, "@QtyReserved", DbType.Int32, a_Product.QtyReserved);
                database.AddInParameter(dbCommand, "@QtyAvailable", DbType.Int32, a_Product.QtyAvailable);
                database.AddInParameter(dbCommand, "@Weight", DbType.Double, a_Product.Weight);
                database.AddInParameter(dbCommand, "@IntroDate", DbType.DateTime, a_Product.IntroDate);
                database.AddInParameter(dbCommand, "@ClickCount", DbType.Int32, a_Product.ClickCount);
                database.AddInParameter(dbCommand, "@RatingAvg", DbType.Int32, a_Product.RatingAvg);
                database.AddInParameter(dbCommand, "@RatingCount", DbType.Int32, a_Product.RatingCount);
                database.AddInParameter(dbCommand, "@Image_hasS", DbType.Boolean, a_Product.Image_hasS);
                database.AddInParameter(dbCommand, "@Image_hasM", DbType.Boolean, a_Product.Image_hasM);
                database.AddInParameter(dbCommand, "@Image_hasL", DbType.Boolean, a_Product.Image_hasL);
                database.AddInParameter(dbCommand, "@LibImageName", DbType.AnsiString, a_Product.LibImageName);
                database.AddInParameter(dbCommand, "@IsDelete", DbType.Boolean, a_Product.IsDelete);
                database.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, a_Product.IsActive);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_Product.DomainID);
                database.AddInParameter(dbCommand, "@IsPromoEligible", DbType.Boolean, a_Product.IsPromoEligible);
                database.AddInParameter(dbCommand, "@TempProdID", DbType.Int32, a_Product.TempProdID);
                database.AddInParameter(dbCommand, "@TempParentID", DbType.Int32, a_Product.TempParentID);
                database.AddInParameter(dbCommand, "@Custom1", DbType.AnsiString, a_Product.Custom1);
                database.AddInParameter(dbCommand, "@Custom2", DbType.AnsiString, a_Product.Custom2);
                database.AddInParameter(dbCommand, "@Custom3", DbType.AnsiString, a_Product.Custom3);
                database.AddInParameter(dbCommand, "@Custom4", DbType.AnsiString, a_Product.Custom4);
                database.AddInParameter(dbCommand, "@CustomDate", DbType.DateTime, a_Product.CustomDate);
                database.AddInParameter(dbCommand, "@IsTaxable", DbType.Boolean, a_Product.IsTaxable);
                database.AddInParameter(dbCommand, "@IsShippable", DbType.Boolean, a_Product.IsShippable);
                database.AddInParameter(dbCommand, "@IsGiftCert", DbType.Boolean, a_Product.IsGiftCert);
                database.AddInParameter(dbCommand, "@IsPackage", DbType.Boolean, a_Product.IsPackage);
                database.AddInParameter(dbCommand, "@NumImages", DbType.Byte, a_Product.NumImages);
                database.AddInParameter(dbCommand, "@NumPDFs", DbType.Byte, a_Product.NumPDFs);
                database.AddInParameter(dbCommand, "@NumVideos", DbType.Byte, a_Product.NumVideos);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_Product methods
        public virtual void Deletea_Product(int prodID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Products_del");
                
                database.AddInParameter(dbCommand, "@ProdID", DbType.Int32, prodID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_Product methods
        
        public virtual a_Product Geta_Product(int prodID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Products_sel");
                
                database.AddInParameter(dbCommand, "@ProdID", DbType.Int32, prodID);
                
                a_Product a_Product =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_Product = Createa_ProductFromReader(reader);
                        reader.Close();
                    }
                }
                return a_Product;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_ProductList methods
        public virtual a_ProductCollection Geta_ProductList(a_ProductColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Products_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_ProductCollection a_ProductCollection = new a_ProductCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_Product a_Product = Createa_ProductFromReader(reader);
                        a_ProductCollection.Add(a_Product);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_ProductCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_ProductCollection Geta_ProductList(a_ProductColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_ProductList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}